from Movable import Movable
import Debug
import Helper
import UAI
class Person(Movable):
    name         = 'Person'
    team         = None
    color        = (  0,  0,255)
    width        = 20
    height       = 20
    hideFromList = []
    inHiding     = False
    state        = 'STOPPED'
    
    
    def __init__(self, pos, team, color = (0,0,255)):
        Movable.__init__(self, pos)
        self.setColor(color)
        self.team = team
    
    def isHiding(self):
        return self.inHiding
    
    def hideFrom(self, scaryitem):
        self.hidefromlist.append(scaryitem)
    
    def run(self):
        if self.hideFromList:
            if not self.isHiding():
                for item in self.hideFromList:
                    if not Helper.obsticleInBetweenRects(self.rect, item.rect):
                        self.hide(item.pos)
            elif not self.targets:
                self.stop()
        Movable.run(self)
    
    def setState(self, state):
        self.state = state
        self.overlayText(state)
            
    def hide(self, pos):
        '''
        TODO: Fix this, it works, but with glitches
        '''
        self.setState('Hiding')
        self.stop()
        node = UAI.pathfinding.searchForHiding(self.rect.center, pos) # looks at center -> pos, but should look for rect -> rect view
        while node:
            self.addTarget(node.pos, 0, True)
            node = node.parent
        self.hiding = True

    def move(self, pos):
        self.setState('Moving')
        self.addTarget(pos)
    
    def shoot(self, pos):
        self.setState('Shooting')
    
    def stop(self, time=0):
        self.setState('Stopped')
        self.hiding = False
        self.targets = []